package com.xuecheng.api.client;

import com.xuecheng.api.client.fallback.MediaClientFallBackFactory;
import com.xuecheng.api.config.MultipartSupportConfig;
import com.xuecheng.api.dto.MediaFiles;
import com.xuecheng.api.dto.UploadFileResultDTO;
import com.xuecheng.base.result.RestResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: 媒资管理客户端
 * @date 2025/2/16 14:23
 */
@FeignClient(value = "media-api", fallbackFactory = MediaClientFallBackFactory.class, configuration = MultipartSupportConfig.class)
public interface MediaClient {

    /**
     * 根据文件id查询文件信息
     *
     * @param mediaId 文件id
     * @return 文件信息
     */
    @GetMapping("/media/media-files/{mediaId}")
    MediaFiles queryMediaById(@PathVariable("mediaId") String mediaId);

    /**
     * 上传文件
     * @param file 文件
     * @param courseId 课程id
     * @return 文件信息
     */
    @PostMapping(value = "/media/upload/course-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    UploadFileResultDTO upload(@RequestPart("filedata") MultipartFile file, @RequestParam(required = false, value = "courseId") Long courseId);

    /**
     * 删除文件
     *
     * @param id 文件id
     * @return 删除结果
     */
    @DeleteMapping("/media/course-files/{courseId}")
    RestResponse<Boolean> deleteCourseHtml(@PathVariable("courseId") Long courseId);
}
